package LeetCode;

public class No53 {
    public static void main(String[] args) {
        int[] a = {5,4,-1,7,8};
        System.out.println(maxSubArray(a));
    }

    public static int maxSubArray(int[] nums) {
        int max = nums[0];
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
            max = Math.max(max,sum);
            if(sum<0) sum=0;
        }
        return max;
    }
}
